//
// Created by Win10 on 2022/10/31.
//

#include<iostream>
#include "sq_stack.h"

using namespace std;

void InitStack(SqStack &S) {
    S.top = -1;
}

bool StackEmpty(SqStack S) {
    if (S.top == -1) {
        return true;
    }
    return false;
}

bool Push(SqStack &S, ElemType x) {
    if (S.top == MaxSize - 1) {
        return false;
    }
    S.data[++S.top] = x;
    return true;
}

bool Pop(SqStack &S, ElemType &x) {
    if (S.top == -1) return false;
    x = S.data[S.top--];
    return true;
}

bool GetTop(SqStack S, ElemType &x) {
    if (S.top == -1) return false;
    x = S.data[S.top];
    return true;
}

int main() {
    {
        SqStack S;
        InitStack(S);
        for (int i = 0; i <= 5; i++) {
            Push(S, i);
        }
        ElemType x;
        GetTop(S, x);
        cout << x << endl;
        while (!StackEmpty(S)) {
            Pop(S, x);
            cout << x << endl;
        }
    }
    return 0;
}